﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class FieldDutyDtlsBLL : IFieldDutyDtlsBLL
    {
        private static readonly IFieldDutyDtlsDAL DAL = DataAccess.CreateFieldDutyDetails();

        private FieldDutyDtlsInfo dtInfo = new FieldDutyDtlsInfo();
        private FieldDutyInfo dInfo = new FieldDutyInfo();
        private DutyInfo dutyInfo = new DutyInfo();
        private FieldInfo fInfo = new FieldInfo();
        private ClassInfo cInfo = new ClassInfo();

        public DataSet LoadFieldDutyDetails(Nullable<int> Sequence, Nullable<int> FieldDutySeq)
        {
            dtInfo.Sequence = Sequence.HasValue ? (int)Sequence : 0;
            dInfo.Sequence = FieldDutySeq.HasValue ? (int)FieldDutySeq : 0;
            dtInfo.FieldDuty = dInfo;

            return DAL.LoadFieldDutyDetails(dtInfo);
        }
        public void Insert(string Field, string Class, string Duty, string No, string Description, int CreatedBy)
        {
            if (Field.Length > 0)
                fInfo.Sequence = Int32.Parse(Field);
            if (Class.Length > 0)
                cInfo.Sequence = Int32.Parse(Class);
            if (Duty.Length > 0)
                dutyInfo.Sequence = Int32.Parse(Duty);

            dInfo.Field = fInfo;
            dInfo.Class = cInfo;
            try
            {
                DAL.Insert(new FieldDutyDtlsInfo(0, dInfo, dutyInfo, No, Description, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, int FieldDuty, string Duty, string No, string Description, int UpdatedBy)
        {
            if (FieldDuty > 0)
                dInfo.Sequence = FieldDuty;
            if (Duty.Length > 0)
                dutyInfo.Sequence = Int32.Parse(Duty);
            try
            {
                DAL.Update(new FieldDutyDtlsInfo(Sequence, dInfo, dutyInfo, No, Description, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
        
    }
}
